knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)

library(tidyverse)
library(here)
library(janitor)
library(sf)
library(tmap)

Data Overview

This analysis visualizes California oil spill incident data for 2008, provided by the Office of Spill Prevention and Response. For this data set, an “incident” is defined as “a discharge or threatened discharge of petroleum or other deleterious material into the waters of the state”(Lampinen, 2020). The two maps included in this report are an interactive map of all 2008 spill incidents in California, and a choropleth map of all inland oil spill incidents by county.

### Read in the data

ca_counties_sf <- read_sf(here("data", "ca_counties", "CA_Counties_TIGER2016.shp")) %>% 
  clean_names() %>% 
  select(county_name = namelsad, land_area = aland)

oil_spills <- read_csv(here("data", "Oil_Spill_Incident_Tracking_[ds394].csv")) %>% 
  clean_names()

Interactive Tmap

### Check CRS

# ca_counties_sf %>% st_crs() ### EPSG 3857, WGS 84

### Make oil_spill data frame sf

oil_spills_sf <- st_as_sf(oil_spills, coords=c("x","y"), crs = st_crs(ca_counties_sf))
tmap_mode(mode = "view")

tm_shape(ca_counties_sf) +
  tm_polygons(alpha = 0.5) +
  tm_shape(oil_spills_sf)+
  tm_dots(col = "orange")

Figure 1: An interactive map of all oil spill incidents in California in 2008.

Choropleth Map

### Subset inland oil spills

oil_inland <- oil_spills_sf %>% 
  filter(inlandmari %in% "Inland")

### Spatial join to find count of inland spills by county

county_oil_sf <- ca_counties_sf %>% 
  st_join(oil_inland)

### Group by and summarize to get counts

county_oil_count_sf <- county_oil_sf %>% 
  group_by(county_name) %>%
  summarize(n_records = sum(!is.na(dfgcontrol)))
### Create choropleth

ggplot()+
  geom_sf(data= county_oil_count_sf, aes(fill = n_records), color ="black", size = 0.1) +
  scale_fill_gradientn(colors = c("yellow","orange","red")) +
  theme_minimal() +
  labs(fill = "Count of oil spill incidents")

Figure 2: Choropleth visualizing California counties based on the count of inland oil incidents for 2008. Red indicates counties with a high number of incidents.

Data Citation

Lampinen, Mark (2020). Oil Spill Incident Tracking [ds394]. California Department of Fish and Game, Office of Spill Prevention and Response. https://gis.data.ca.gov/datasets/CDFW::oil-spill-incident-tracking-ds394-1/about